package jifenbao.com.jifenbao;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import java.util.Timer;
import java.util.TimerTask;

/**
 * Created by Administrator on 2016/6/3 0003.
 */
public class Button_Test extends Activity{
    private Button buttonsend;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.send_button_test);

        buttonsend = (Button)findViewById(R.id.send222_btn);
        buttonsend.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                buttonsend.setEnabled(false);
                count();
            }
        });
    }

    public void count(){
        final Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            int time = 10;
            @Override
            public void run() {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        time--;
                        if (time<=0){
                            timer.cancel();
                            buttonsend.setText("重新发送");
                            buttonsend.setEnabled(true);
                        }else{
                            buttonsend.setText("已发送"+time+"s");
                        }
                    }
                });
            }
        },0,1000);
    }
}
